package com.wander.patterns.create.prototype;

import java.util.Date;

/**
 * @description: 原型模式
 * TODO  浅克隆
 * TODO  深克隆
 * @author: zhuyong
 * @create: 2019-09-06 16:13
 **/
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        Date date = new Date(1567759598000L);
        Sheep sheep = new Sheep();
        sheep.setName("多利羊的克隆体");
        sheep.setAge(1);
        sheep.setSex(1);
        sheep.setBirthDay(date);
        System.out.println(sheep.getName()+"="+sheep.getBirthDay());

        date.setTime(1565081198000L);
        //若此时修改 date
        //duoLiSheep.birthDay 的值随着变了  那就是 浅复制
        //深复制 : duoLiSheep 时间是改过的时间  sheep 是原始的数据
        //反之,clone()
        Sheep duoLiSheep =(Sheep) sheep.clone();//取决于clone() 是否拷贝属性值
        duoLiSheep.setName("多利羊");
        System.out.println(duoLiSheep.getName()+"="+duoLiSheep.getBirthDay());


        //res :
        //多利羊的克隆体=Fri Sep 06 16:46:38 CST 2019
        //多利羊=Tue Aug 06 16:46:38 CST 2019
    }


}
